# -*- encoding=utf8 -*-
import datetime
import time

from selenium.webdriver.common.by import By

from base.base import Base
import page


class PageExamScheduler(Base):

    #应用平铺
    def __card_icon(self):
        if(self.element_is_displayed(page.card_icon)):
            self.element_click(page.card_icon)

    # 点击进入排考
    def __clickCard(self):
        self.element_click(page.exam_card)
        self.swich_newWindows()


    def __clickConfirm(self):
        if(self.element_is_displayed(page.gotIt_btn)):
            self.element_JsClick(page.gotIt_btn)

    def __newExamSchedule(self):
        time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        self.element_JsClick(page.new_exam)
        self.element_input(page.exam_name,time_now)
        self.element_click(page.ScoreTypeId)
        self.element_click(page.monthlyTest)
        self.element_JsClick(page.confirm_btn)

    def __addGrade(self):
        self.element_click(page.gradeList)
        self.element_click(page.chooseGrade)
        self.element_JsClick(page.addGrade)

    def testExamScheduler(self):
        self.__card_icon()
        self.__clickCard()
        self.__clickConfirm()
        self.__newExamSchedule()
        self.__addGrade()
        self.get_screenshot()
        self.element_JsClick(page.submit)
        time.sleep(2)
        for i in range(9):
            self.element_input((By.XPATH,'//tr[@data-row-key="{index}"]//input'.format(index=i)),"90")
        self.element_JsClick(page.nextSetp)
        time.sleep(2)
        self.element_JsClick(page.nextSetp)
        time.sleep(2)

        #设置分页
        self.element_click(page.paOption)
        self.element_click(page.paginatcount)

        #全选当前页面教师
        self.element_click(page.selectAll)
        time.sleep(1)

        #批量设置监考
        self.element_JsClick(page.batchSelect)
        time.sleep(1)
        self.element_click(page.invigilate )
        self.element_JsClick(page.confirm_btn)

        self.element_JsClick(page.nextSetp)
        time.sleep(2)
        self.element_JsClick(page.submitSettings)